﻿using System;
using System.Collections.Generic;
using System.ServiceModel.Activation;
using System.Web;
using Domaine;
using Ninject;
using Persistance;
using Persistance.ViewModel;
using WebServices.Infrastructure;

namespace WebServices
{
    
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ExaPlanningService : IExaPlanningService
    {
        [Inject]
        public IGestionCompte GestionCompte { get; set; }

        [Inject]
        public IGestionProjet GestionProjet { get; set; }

        [Inject]
        public CustomValidator CustomValidator { get; set; }

        #region LogIn
        public CollaboratorViewModel LogInJSON(string login, string password)
        {
            CustomValidator.Validate(login,password);
            return LogIn();
        }

        public CollaboratorViewModel LogIn()
        {
            var login = HttpContext.Current.Session["login"];
            return GestionCompte.getCollabLoggedIn(login.ToString());
        }
        #endregion

        #region GetCalendarYear
        public CalendarYear GetCalendarYearJSON(string login, string password, int year)
        {
            CustomValidator.Validate(login, password);
            return GetCalendarYear(year);
        }

        public CalendarYear GetCalendarYear(int year)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetCalendarYear(login.ToString(), year);
        }

        #endregion

        #region GetCalendarMonth
        public CalendarMonth GetCalendarMonthJSON(string login, string password, int year, int month)
        {
            CustomValidator.Validate(login, password);
            return GetCalendarMonth(year, month);
        }

        public CalendarMonth GetCalendarMonth(int year, int month)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetCalendarMonth(login.ToString(), year, month);
        }
        #endregion

        #region GetCalendarWeek
        public CalendarWeek GetCalendarWeekJSON(string login, string password, int fyear, int fmonth, int fday, int lyear, int lmonth, int lday)
        {
            CustomValidator.Validate(login, password);
            return GetCalendarWeek(fyear, fmonth, fday, lyear, lmonth, lday);
        }

        public CalendarWeek GetCalendarWeek(int fyear, int fmonth, int fday, int lyear, int lmonth, int lday)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetCalendarWeek(login.ToString(), fyear, fmonth, fday, lyear, lmonth, lday);
        }
        #endregion

        #region GetProjectCalendarYear
        public CalendarYear GetProjectCalendarYearJSON(string login, string password, int year, string reference)
        {
            CustomValidator.Validate(login, password);
            return GetProjectCalendarYear(year, reference);
        }

        public CalendarYear GetProjectCalendarYear(int year, string reference)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetProjectCalendarYear(login.ToString(), year, reference);
        }

        #endregion

        #region GetProjectCalendarMonth
        public CalendarMonth GetProjectCalendarMonthJSON(string login, string password, int year, int month, string reference)
        {
            CustomValidator.Validate(login, password);
            return GetProjectCalendarMonth(year, month, reference);
        }

        public CalendarMonth GetProjectCalendarMonth(int year, int month, string reference)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetProjectCalendarMonth(login.ToString(), year, month, reference);
        }
        #endregion

        #region GetProjectCalendarWeek
        public CalendarWeek GetProjectCalendarWeekJSON(string login, string password, int fyear, int fmonth, int fday, int lyear, int lmonth, int lday, string reference)
        {
            CustomValidator.Validate(login, password);
            return GetProjectCalendarWeek(fyear, fmonth, fday, lyear, lmonth, lday, reference);
        }

        public CalendarWeek GetProjectCalendarWeek(int fyear, int fmonth, int fday, int lyear, int lmonth, int lday, string reference)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetProjectCalendarWeek(login.ToString(), fyear, fmonth, fday, lyear, lmonth, lday, reference);
        }
        #endregion

        #region GetAllProjectForYear
        public List<ProjectFullDetailModel> GetAllProjectForYearJSON(string login, string password, int year)
        {
            CustomValidator.Validate(login, password);
            return GetAllProjectForYear(year);
        }

        public List<ProjectFullDetailModel> GetAllProjectForYear(int year)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetAllProjectForYear(login.ToString(), year);
        }
        #endregion 

        #region GetProject
        public ProjectFullDetailModel GetProjectJSON(string login, string password, string reference)
        {
            CustomValidator.Validate(login, password);
            return GetProject(reference);
        }

        public ProjectFullDetailModel GetProject(string reference)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetProject(login.ToString(), reference);
        }
        #endregion 
        
        #region GetLeaderProject

        public List<LeaderProjectSimpleModel> GetLeaderProjectJSON(string login, string password, string critere)
        {
            CustomValidator.Validate(login, password);
            return GetLeaderProject(critere);
        }

        public List<LeaderProjectSimpleModel> GetLeaderProject(string critere)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetLeaderProject(critere);
        }
        #endregion

        #region GetCollaborators

        public List<CollaboratorViewModel> GetCollaboratorsJSON(string login, string password, string critere)
        {
            CustomValidator.Validate(login, password);
            return GetCollaborators(critere);
        }

        public List<CollaboratorViewModel> GetCollaborators(string critere)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetCollaborators(critere);
        }
        #endregion

        #region AddProject

        public void AddProjectJSON(string login, string password, string reference, string name, DateTime beginDate, DateTime endDate, string client, string color, string loginCP)
        {
            CustomValidator.Validate(login, password);
            AddProject(reference, name, beginDate, endDate, client, color, loginCP);
        }

        public void AddProject(string reference, string name, DateTime beginDate, DateTime endDate, string client, string color, string loginCP)
        {
            var login = HttpContext.Current.Session["login"];
            GestionProjet.AddProject(login.ToString(), reference, name, beginDate, endDate, client, color, loginCP);
        }
        #endregion

        #region EditProject

        public void EditProjectJSON(string login, string password, string reference, string name, DateTime beginDate, DateTime endDate, int state, string client, string color)
        {
            CustomValidator.Validate(login, password);
            EditProject(reference, name, beginDate, endDate, state, client, color);
        }

        public void EditProject(string reference, string name, DateTime beginDate, DateTime endDate, int state, string client, string color)
        {
            var login = HttpContext.Current.Session["login"];
            GestionProjet.EditProject(login.ToString(), reference, name, beginDate, endDate, state, client, color);
        }
        #endregion

        #region GetTeamProject
        public List<CollaboratorViewModel> GetTeamProjectJSON(string login, string password, string reference)
        {
            CustomValidator.Validate(login, password);
            return GetTeamProject(reference);
        }

        public List<CollaboratorViewModel> GetTeamProject(string reference)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetTeamProject(login.ToString(), reference);
        }
        #endregion 

        #region AddCollabToTeamProject
        public void AddCollabToTeamProjectJSON(string login, string password, string reference, string loginCollab)
        {
            CustomValidator.Validate(login, password);
            AddCollabToTeamProject(reference, loginCollab);
        }

        public void AddCollabToTeamProject(string reference, string loginCollab)
        {
            var login = HttpContext.Current.Session["login"];
            GestionProjet.AddCollabToTeamProject(login.ToString(), reference, loginCollab);
        }
        #endregion 

        #region RemoveCollabFromTeamProject
        public void RemoveCollabFromTeamProjectJSON(string login, string password, string reference, string loginCollab)
        {
            CustomValidator.Validate(login, password);
            RemoveCollabFromTeamProject(reference, loginCollab);
        }

        public void RemoveCollabFromTeamProject(string reference, string loginCollab)
        {
            var login = HttpContext.Current.Session["login"];
            GestionProjet.RemoveCollabFromTeamProject(login.ToString(), reference, loginCollab);
        }
        #endregion 

        #region GetAllState
        public List<Persistance.ViewModel.State> GetAllStateJSON(string login, string password)
        {
            CustomValidator.Validate(login, password);
            return GetAllState();
        }


        public List<Persistance.ViewModel.State> GetAllState()
        {
            return GestionProjet.GetAllState();
        }
        #endregion

        #region GetAllLocation

        public List<LocationViewModel> GetAllLocationJSON()
        {
            return GetAllLocation();
        }

        public List<LocationViewModel> GetAllLocation()
        {
            return GestionCompte.GetAllLocation();
        }

        #endregion

        #region GetAllActivity

        public List<ActivityViewModel> GetAllActivityJSON()
        {
            return GetAllActivity();
        }

        public List<ActivityViewModel> GetAllActivity()
        {
            return GestionCompte.GetAllActivity();
        }

        #endregion

        #region GetAllJob

        public List<JobViewModel> GetAllJobJSON()
        {
            return GetAllJob();
        }

        public List<JobViewModel> GetAllJob()
        {
            return GestionCompte.GetAllJob();
        }

        #endregion

        #region Register
        public void RegisterJSON(String login, string password, string loginNewCollab, string passwordNewCollab, string name, string firstName, string mobilePhone, string email, int job, int location, int activity)
        {
            CustomValidator.Validate(login, password);
            Register(loginNewCollab, passwordNewCollab,name, firstName, mobilePhone, email, job, location, activity);

        }

        public void Register(string loginNewCollab, string passwordNewCollab, string name, string firstName, string mobilePhone, string email, int job, int location, int activity)
        {
            var login = HttpContext.Current.Session["login"];
            GestionCompte.Register(login.ToString(), loginNewCollab, passwordNewCollab, name, firstName, mobilePhone, email, job, location, activity);
        }
        #endregion

        #region EditProfile
        public void EditProfileJSON(string login, string oldPassword, string newPassword, string name, string firstName, string mobilePhone, string email, byte[] image)
        {
            CustomValidator.Validate(login, oldPassword);
            EditProfile(newPassword, name, firstName, mobilePhone, email, image);
        }

        public void EditProfile( string newPassword, string name, string firstName, string mobilePhone, string email, byte[] image)
        {
            var login = HttpContext.Current.Session["login"];
            GestionCompte.EditProfile( login.ToString(), newPassword, name, firstName, mobilePhone, email, image);
        }
        #endregion

        #region EditCollab
        public void EditCollabJSON(string login, string password, string loginCollab, int job, int activity, int location)
        {
            CustomValidator.Validate(login, password);
            EditCollab( loginCollab, job, activity, location);
        }

        public void EditCollab(string loginCollab, int job, int activity, int location)
        {
            var login = HttpContext.Current.Session["login"];
            GestionCompte.EditCollab( login.ToString(), loginCollab, job, activity, location);
        }
        #endregion
        
        #region DeleteCollab
        public void DeleteCollabJSON(string login, string password,string loginCollab)
        {
            CustomValidator.Validate(login, password);
            DeleteCollab(loginCollab);
        }

        public void DeleteCollab(string loginCollab)
        {
            var login = HttpContext.Current.Session["login"];
            GestionCompte.DeleteCollab(login.ToString(), loginCollab);
        }
        #endregion

        #region AddTasks
        public void AddTasksJSON(string login, string password, List<TaskViewModel> tasks)
        {
            CustomValidator.Validate(login, password);
            AddTasks(tasks);
        }

        public void AddTasks(List<TaskViewModel> tasks)
        {
            var login = HttpContext.Current.Session["login"];
            GestionProjet.AddTasks(login.ToString(), tasks);
        }
        #endregion

        #region EditTask
        public void EditTaskJSON(string login, string password, int idTask, TaskViewModel task)
        {
            CustomValidator.Validate(login, password);
            EditTask(idTask, task );
        }

        public void EditTask(int idTask, TaskViewModel task)
        {
            var login = HttpContext.Current.Session["login"];
            GestionProjet.EditTask(login.ToString(), idTask, task);
        }
        #endregion

        #region DeleteTask
        public void DeleteTaskJSON(string login, string password, int idTask)
        {
            CustomValidator.Validate(login, password);
            DeleteTask(idTask);
        }

        public void DeleteTask(int idTask)
        {
            var login = HttpContext.Current.Session["login"];
            GestionProjet.DeleteTask(login.ToString(), idTask);
        }
        #endregion
        
        #region GetTask
        public TaskViewModel GetTaskJSON(string login, string password, int idTask)
        {
            CustomValidator.Validate(login, password);
            return GetTask(idTask);
        }

        public TaskViewModel GetTask(int idTask)
        {
            var login = HttpContext.Current.Session["login"];
            return GestionProjet.GetTask(login.ToString(), idTask);
        }
        #endregion
    }

}
